import _ from 'lodash'

const state = {}

const actions = {
  async modelSetWithServer({ commit, state }, payload){
    try {
      let response = {}
      switch (payload.path) {
        case 'list':
          response = await Promise.resolve([1, 2, 3])
          break
      }
      commit('modelSet', { path: payload.path, data: response.data })
      return response
    } catch (e) {
      return Promise.reject(e)
    }
  },
}
const mutations = {
  modelSet: (state, payload) => {
    _.set(state, payload.path, payload.data)
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
